package config

import (
	"strings"

	"github.com/spf13/viper"
)

func MustLoad(file string, v any) {
	viper.SetConfigType("yaml")
	viper.AddConfigPath(file[:strings.LastIndex(file, "/")+1])
	filename := file[strings.LastIndex(file, "/")+1 : strings.LastIndex(file, ".")]
	viper.SetConfigName(filename)

	if err := viper.ReadInConfig(); err != nil {
		panic(err)
	}
	if err := viper.Unmarshal(v); err != nil {
		panic(err)
	}
}
